//
//  WBNavigationViewController.swift
//  Weibo
//
//  Created by eju_wangzhenxing on 16/11/4.
//  Copyright © 2016年 qisitianxia. All rights reserved.
//

import UIKit

class WBNavigationViewController: UINavigationController {

    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigationBar.isHidden = true
    }
    
    // 重新 push方法 隐藏 底部tabbar
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        print(viewControllers.count)
        
        //如果不是栈底控制器 需要隐藏  
        
        if childViewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            
            //判断控制器类型
            if let vc = viewController as? WBBaseViewController {
                
                var title = "返回"
                
                // 判断控制器的级数
                
                if childViewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? "返回"
                }
                
                //取出自定义的 navItem
                vc.navItem.leftBarButtonItem = UIBarButtonItem.init(title: title, titleFontSize: 16, target: self, action: #selector(popEvent), isBack: true)
            }
        }
        
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc private func popEvent() {
        popViewController(animated: true)
    }
}
